import type { RouteRecordStringComponent } from '@vben-core/typings';

import type { PageResult } from '#/type/base_beans';
import type { SysMenuReq, SysMenuResp } from '#/type/sys_menu';

import { requestClient } from '#/api/request';

const API_PREFIX = '/sys/menu';

/**
 * 获取所有菜单
 */
export async function getAllMenusApi() {
  return requestClient.get<RouteRecordStringComponent[]>(`${API_PREFIX}/all`);
}

export async function getMenuByIdApi(id: string) {
  return requestClient.get<SysMenuResp>(`${API_PREFIX}/get_by_id/${id}`);
}

export async function getMenuListApi(params: SysMenuReq) {
  return requestClient.get<Array<SysMenuResp>>(`${API_PREFIX}/list`, {
    params,
  });
}

export async function getMenuPageApi(params: SysMenuReq) {
  return requestClient.get<PageResult<SysMenuResp>>(`${API_PREFIX}/page`, {
    params,
  });
}

export async function createMenuApi(data: SysMenuReq) {
  return requestClient.post<Promise<void>>(`${API_PREFIX}/create`, data);
}

export async function editMenuApi(data: SysMenuReq) {
  return requestClient.put<Promise<void>>(`${API_PREFIX}/edit`, data);
}

export async function createEditMenuApi(data: SysMenuReq) {
  return requestClient.post<Promise<void>>(`${API_PREFIX}/create_edit`, data);
}

export async function deleteMenuApi(ids: Array<string>) {
  return requestClient.delete<Promise<void>>(`${API_PREFIX}/delete`, {
    params: { ids },
  });
}
